package com.ctsi.ssdc.controller;

import com.ctsi.ssdc.entity.Excel08VO.Excel15VO;
import com.ctsi.ssdc.entity.Excel15;
import com.ctsi.ssdc.entity.SocialRetailSales;
import com.ctsi.ssdc.entity.TradeAndServiceIndustry;
import com.ctsi.ssdc.service.Excel15Service;
import com.ctsi.ssdc.service.ExcelService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 15基础表贸易分行业(Excel15)表控制层
 *
 * @author makejava
 * @since 2023-02-21 16:26:42
 */
@RestController
@RequestMapping("excel/15")
public class Excel15Controller {
    /**
     * 服务对象
     */
    @Resource
    private Excel15Service excel15Service;
    @Resource
    private ExcelService excelService;

    /**
     * 分页查询
     *
     * @param excel15     筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Excel15>> queryByPage(Excel15 excel15, @PageableDefault Pageable pageRequest) {
        return ResponseEntity.ok(this.excel15Service.queryByPage(excel15, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Excel15> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.excel15Service.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param excel15 实体
     * @return 新增结果
     */
    @PostMapping
    @Transactional(rollbackFor = Exception.class)
    public ResponseEntity<Excel15> add(Excel15 excel15) {
        Excel15 insert = this.excel15Service.insert(excel15);
        excelService.sheet15Cal(excel15.getStatisticalTime());
        return ResponseEntity.ok(insert);
    }

    /**
     * 编辑数据
     *
     * @param excel15 实体
     * @return 编辑结果
     */
    @PutMapping
    @Transactional(rollbackFor = Exception.class)
    public ResponseEntity<Excel15> edit(Excel15 excel15) {
        Excel15 update = this.excel15Service.update(excel15);
        excelService.sheet15Cal(excel15.getStatisticalTime());
        return ResponseEntity.ok(update);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    @Transactional(rollbackFor = Exception.class)
    public ResponseEntity<Boolean> deleteById(Long id) {
        Excel15 excel15 = excel15Service.queryById(id);
        boolean res = this.excel15Service.deleteById(id);
        excelService.sheet15Cal(excel15.getStatisticalTime());
        return ResponseEntity.ok(res);
    }

    /**
     * 重点服务业企业销售完成情况
     * @param year
     * @param month
     * @return
     */
    @GetMapping("info/{year}/{month}")
    @ApiOperation("重点服务业企业销售完成情况")
    public ResponseEntity<List<Excel15VO>> keyInfo(@PathVariable("year") String year,
                                                   @PathVariable("month") String month) {
        return ResponseEntity.ok(this.excel15Service.keyInfo(year,month));
    }

    /**
     * 批零住餐总营业额当月 + 累计 + 同比:（本期累计/同期累计-1）*100%
     * @param year
     * @param month
     * @return
     */
    @GetMapping("turnoverTotal/{year}/{month}")
    @ApiOperation("批零住餐营业额当月 + 累计 + 同比:（本期累计/同期累计-1）*100%")
    public ResponseEntity<TradeAndServiceIndustry> getTurnoverTotal(@PathVariable("year") String year,
                                                                    @PathVariable("month") String month) {
        return ResponseEntity.ok(excel15Service.getTurnoverTotal(year,month));
    }

    /**
     * 批发业营业额当月 + 累计 + 同比:（本期累计/同期累计-1）*100%
     * @param year
     * @param month
     * @return
     */
    @GetMapping("wholesaleTurnoverTotal/{year}/{month}")
    @ApiOperation("批发业营业额当月 + 累计 + 同比:（本期累计/同期累计-1）*100%")
    public ResponseEntity<TradeAndServiceIndustry> getWholesaleTurnoverTotal(@PathVariable("year") String year,
                                                                    @PathVariable("month") String month) {
        return ResponseEntity.ok(excel15Service.getWholesaleTurnoverTotal(year,month));
    }

    /**
     * 零售业营业额当月 + 累计 + 同比:（本期累计/同期累计-1）*100%
     * @param year
     * @param month
     * @return
     */
    @GetMapping("retailTurnoverTotal/{year}/{month}")
    @ApiOperation("零售业营业额当月 + 累计 + 同比:（本期累计/同期累计-1）*100%")
    public ResponseEntity<TradeAndServiceIndustry> getRetailTurnoverTotal(@PathVariable("year") String year,
                                                                    @PathVariable("month") String month) {
        return ResponseEntity.ok(excel15Service.getRetailTurnoverTotal(year,month));
    }


    /**
     * 住宿业营业额当月 + 累计 + 同比:（本期累计/同期累计-1）*100%
     * @param year
     * @param month
     * @return
     */
    @GetMapping("lodgingTurnoverTotal/{year}/{month}")
    @ApiOperation("住宿业营业额当月 + 累计 + 同比:（本期累计/同期累计-1）*100%")
    public ResponseEntity<TradeAndServiceIndustry> getLodgingTurnoverTotal(@PathVariable("year") String year,
                                                                    @PathVariable("month") String month) {
        return ResponseEntity.ok(excel15Service.getLodgingTurnoverTotal(year,month));
    }

    /**
     * 餐饮业营业额当月 + 累计 + 同比:（本期累计/同期累计-1）*100%
     * @param year
     * @param month
     * @return
     */
    @GetMapping("cateringTurnoverTotal/{year}/{month}")
    @ApiOperation("餐饮业营业额当月 + 累计 + 同比:（本期累计/同期累计-1）*100%")
    public ResponseEntity<TradeAndServiceIndustry> getCateringTurnoverTotal(@PathVariable("year") String year,
                                                                           @PathVariable("month") String month) {
        return ResponseEntity.ok(excel15Service.getCateringTurnoverTotal(year,month));
    }
}

